//
//  SYTuDiShiXunJiLuView.m
//  SanYiTeaching
//
//  Created by 郑浩然 on 2019/4/24.
//  Copyright © 2019年 SanYi. All rights reserved.
//

#import "SYTuDiShiXunJiLuView.h"
#import "SYShiXunHeaderView.h"
#import "SYWanChengTableViewCell.h"
#import "SYChuangJianView.h"
#import "SYChengYuanDetailsView.h"
#import "SYChengYuanDetailsView.h"


@interface SYTuDiShiXunJiLuView ()<UITableViewDelegate,UITableViewDataSource,SYWanChengTableViewCellDelegate>
@property (nonatomic, strong) SYChuangJianView *createView;//创建
@property (strong, nonatomic) SYBackTopView *backView;//顶部viwe
@property (strong, nonatomic) UITableView *curTableView;// 表
@property (nonatomic, strong) SYChengYuanDetailsView *cyDetailsView;//完成
@end


@implementation SYTuDiShiXunJiLuView

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = [UIColor colorWithHexString:@"#EEEEEE"];
        [self initSubView];
    }
    return self;
}
- (void)initSubView {
    [self addSubview:self.backView];
    [self.backView mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.top.left.right.equalTo(self);
        make.height.mas_equalTo(50);
    }];
    
    //表
    [self addSubview:self.curTableView];
    [self.curTableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.backView.mas_bottom).offset(0);
        make.left.equalTo(self).offset(14);
        make.right.equalTo(self.mas_right).offset(-14);
        make.bottom.equalTo(self.mas_bottom).offset(-14);
    }];
}

#pragma mark - tab
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 2;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 4;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 44;
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
    return 40;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    return 223+40+40;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    SYWanChengTableViewCell *wCell =[tableView dequeueReusableCellWithIdentifier:@"SYWanChengTableViewCell" forIndexPath:indexPath];
    UIColor *color = nil;
    if (indexPath.row%2) {
        color = [UIColor whiteColor];
        
    } else {
        color = [UIColor colorWithHexString:@"F8F8F8"];
    }
    wCell.selectionStyle = UITableViewCellSelectionStyleNone;
    wCell.delegate = self;
//    进行中传入0  已完成传入1
    [wCell incomingDataInteger:1 backColor:color];
    return wCell;
    
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    UIView *view = [UIView new];
    SYShiXunHeaderView *headerView = [[SYShiXunHeaderView alloc] init];
    [view addSubview:headerView];
    [headerView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.equalTo(view).offset(14);
        make.right.equalTo(view).offset(-14);
        make.bottom.equalTo(view.mas_bottom).offset(0);
    }];
    if (section == 0) {
        [headerView shixunHeaderViewType:SYShiXunHeaderViewTypeDetails index:0];
    } else {
        [headerView shixunHeaderViewType:SYShiXunHeaderViewTypeDetails index:0];
    }
    
    return view;
}

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
    UIView *view = [UIView new];
    UIView *topView = [UIView new];
    topView.backgroundColor = [UIColor colorWithHexString:@"F8F8F8"];
    [view addSubview:topView];
    [topView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(view);
        make.left.equalTo(view.mas_left).offset(14);
        make.right.equalTo(view.mas_right).offset(-14);
        make.height.mas_equalTo(20);
    }];
    return view;
}
#pragma mark - cell得代理
//代理
- (void)selectTableViewCellType:(SYWanChengTableViewCellType)type {
    if (type == SYWanChengTableViewCellTypeChaKan) {//查看
        _cyDetailsView = [[SYChengYuanDetailsView alloc] initWithFrame:CGRectMake(kScreen_WIDTH, 0, CGRectGetWidth(self.frame), kScreen_HEIGHT-20)];
        [self addSubview:_cyDetailsView];
        __weak typeof(self) weakSelf = self;
        [UIView animateWithDuration:kAnimate animations:^{
            weakSelf.cyDetailsView.frame = CGRectMake(0, 0, CGRectGetWidth(self.frame), kScreen_HEIGHT-20);
        }];
    } else {//移出
        
    }
}

#pragma mark - set
//头部
- (SYBackTopView *)backView {
    if (!_backView) {
        _backView = [[SYBackTopView alloc] initWithTitleName:@"师训" baseView:self];
    }
    return _backView;
}
- (UITableView *)curTableView {
    if (!_curTableView) {
        _curTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, 0, 0) style:UITableViewStyleGrouped];
        
        _curTableView.delegate = self;
        _curTableView.dataSource = self;
        _curTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        _curTableView.backgroundColor = [UIColor whiteColor];
        [_curTableView registerCellWithClassNames:@[@"SYWanChengTableViewCell"]];
    }
    return _curTableView;
}
@end
